package cn.com.HiSting1990.MyList;

import java.lang.reflect.Field;
import java.util.HashMap;

public class myHashMap {
    public static void main(String[] args) {
        HashMap<Integer, Integer> hashMap = new HashMap<>(1000);

        for (int i=0;i<77;i++){
            hashMap.put(i,i);
        }

        System.out.println("hashMap 容量"+getCapacity(hashMap));
        System.out.println("hashMap 大小"+hashMap.size());
    }

    private static Integer getCapacity(HashMap<Integer,Integer> hashMap){
        Class hashMapClass = hashMap.getClass();
        Integer length = null;
        try {
            Field threshold = hashMapClass.getDeclaredField("threshold");
            threshold.setAccessible(true);
            length = (Integer) threshold.get(hashMap);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return length;
    }
}
